package com.example.tests;

import com.example.utils.SortedListOf;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

/**
 * Created with IntelliJ IDEA.
 * User: pshevchenko
 * Date: 11.03.13
 * Time: 11:45
 * To change this template use File | Settings | File Templates.
 */
public class AddressRemovalTestSet extends TestBase{

    @Test
    public void deleteSomeAddressFromList(){

        //save old state from DB
        SortedListOf<AddressData> oldAddressList
                =new SortedListOf<AddressData>(applicationManager.getModel().getAddressList());

        //get addresses number and check if there are any addresses
        int addressCount = oldAddressList.size();
        if (addressCount == 0)
            return;

        //pick an object to delete
        int randomAddressNumber = applicationManager.getAddressHelper().getRandomIndex(addressCount);

        //delete
        applicationManager.getAddressHelper().deleteAddress(randomAddressNumber);

        //save new state from GUI
        SortedListOf<AddressData> newAddressList
                = applicationManager.getAddressHelper()
                .getGuiAddressList();

        //compare states
        assertThat(newAddressList, equalTo(oldAddressList.without(randomAddressNumber)));
    }
}
